package com.threeonemeeting.list;

import java.util.ArrayList;
import java.util.List;

import com.threeonemeeting.model.MeetingCommentInfo;

public class MeetingCommentInfoList {

	public List<MeetingCommentInfo> listMeetingCommentInfo = new ArrayList<MeetingCommentInfo>();

	public void addCommentInfo(MeetingCommentInfo commentInfo) {
		if (commentInfo == null)
			return;

		MeetingCommentInfo info = getCommentInfo(commentInfo.nCommentId);
		if (info != null)
			return;

		listMeetingCommentInfo.add(commentInfo);
	}

	public MeetingCommentInfo getCommentInfo(int nCommentId) {
		for (int i = 0; i < listMeetingCommentInfo.size(); i++) {
			MeetingCommentInfo info = listMeetingCommentInfo.get(i);
			if (info == null)
				continue;

			if (info.nCommentId == nCommentId)
				return info;
		}

		return null;
	}

	public MeetingCommentInfo getRootCommentInfo(int nCommentId) {
		MeetingCommentInfo info = getCommentInfo(nCommentId);
		if (info == null)
			return null;

		return getCommentInfo(info.nRootId);
	}

	public MeetingCommentInfo getParentCommentInfo(int nCommentId) {
		MeetingCommentInfo info = getCommentInfo(nCommentId);
		if (info == null)
			return null;

		return getCommentInfo(info.nParentId);
	}

	public int size() {
		return listMeetingCommentInfo.size();
	}

	public MeetingCommentInfo get(int nLocation) {
		return listMeetingCommentInfo.get(nLocation);
	}

	public void clear() {
		listMeetingCommentInfo.clear();
	}
}
